<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Entrepot
 *
 * @author Gael
 */
class Entrepot {
    public $id;
    public $site;
    
    
    function __construct($id, $site) {
        $this->id = $id;
        $this->site = $site;
    }

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getSite() {
        return $this->site;
    }

    public function setSite($site) {
        $this->site = $site;
    }

    static public function byId($id){
        try{
            $db= getPdo();
            $rep = $db->query("select * from entrepot where id=$id" );
            while($data =$rep->fetch()){
                $ta= new Entrepot($id, $data['site']);
            }
            
            $rep->closeCursor();
            return $ta;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
            return false;
        }
    }
    static public function all(){
        try{
            $db= getPdo();
            $tab = array();
            
            $rep = $db->query("select * from entrepot  " );
            while($data =$rep->fetch()){
                $tab[$data['id']    ]=new Entrepot($data['id'], $data['site']);
                
            }
            $rep->closeCursor();
            return $tab;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
        }
    } 

}

?>
